#include "MessageQueue.h"

using namespace std;

static MessageQueue *s_SharedMessageQueue = nullptr;

MessageQueue* MessageQueue::getInstance()
{
	if (!s_SharedMessageQueue)
	{
		s_SharedMessageQueue = new (std::nothrow) MessageQueue();
		CCASSERT(s_SharedMessageQueue, "FATAL: Not enough memory");
		s_SharedMessageQueue->init();
	}

	return s_SharedMessageQueue;
}

void MessageQueue::init()
{
	m_queue = new queue<void*>();
}

bool MessageQueue::push(void* mess)
{
	if (m_queue != NULL) 
	{
		m_queue->push(mess);
		return true;
	}

	return false;
}

void* MessageQueue::pop()
{
	void* re = NULL;
	if (m_queue != NULL&&!m_queue->empty())
	{
		re = m_queue->front();
		m_queue->pop();
		return re;
	}
	return re;
}